home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / blt2.4 / treeview.tcl < prev    next >
Encoding:
Text File  |  2009-12-04  |  24.9 KB  |  1,036 lines

  1.  
  2. # ======================================================================
  3. #
  4. # treeview.tcl
  5. #
  6. # ----------------------------------------------------------------------
  7. # Bindings for the BLT treeview widget
  8. # ----------------------------------------------------------------------
  9. #
  10. #   AUTHOR:  George Howlett
  11. #            Bell Labs Innovations for Lucent Technologies
  12. #            gah@lucent.com
  13. #            http://www.tcltk.com/blt
  14. #
  15. #      RCS:  $Id: treeview.tcl,v 1.25 2002/08/06 05:08:24 ghowlett Exp $
  16. #
  17. # ----------------------------------------------------------------------
  18. # Copyright (c) 1998  Lucent Technologies, Inc.
  19. # ----------------------------------------------------------------------
  20. #
  21. # Permission to use, copy, modify, and distribute this software and its
  22. # documentation for any purpose and without fee is hereby granted,
  23. # provided that the above copyright notice appear in all copies and that
  24. # both that the copyright notice and warranty disclaimer appear in
  25. # supporting documentation, and that the names of Lucent Technologies
  26. # any of their entities not be used in advertising or publicity
  27. # pertaining to distribution of the software without specific, written
  28. # prior permission.
  29. #
  30. # Lucent Technologies disclaims all warranties with regard to this
  31. # software, including all implied warranties of merchantability and
  32. # fitness.  In no event shall Lucent be liable for any special, indirect
  33. # or consequential damages or any damages whatsoever resulting from loss
  34. # of use, data or profits, whether in an action of contract, negligence
  35. # or other tortuous action, arising out of or in connection with the use
  36. # or performance of this software.
  37. #
  38. # ======================================================================
  39.  
  40. namespace eval blt::tv {
  41.     set afterId ""
  42.     set scroll 0
  43.     set column ""
  44.     set space   off
  45.     set x 0
  46.     set y 0
  47. }
  48.  
  49. image create photo blt::tv::normalCloseFolder -format gif -data {
  50.     R0lGODlhEAANAMIAAAAAAH9/f///////AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
  51.     AAM8WBrM+rAEQWmIb5KxiWjNInCkV32AJHRlGQBgDA7vdN4vUa8tC78qlrCWmvRKsJTquHkp
  52.     ZTKAsiCtWq0JADs=
  53. }
  54. image create photo blt::tv::normalOpenFolder -format gif -data {
  55.     R0lGODlhEAANAMIAAAAAAH9/f///////AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
  56.     AAM1WBrM+rAEMigJ8c3Kb3OSII6kGABhp1JnaK1VGwjwKwtvHqNzzd263M3H4n2OH1QBwGw6
  57.     nQkAOw==
  58. }
  59. image create photo blt::tv::activeCloseFolder -format gif -data {
  60.     R0lGODlhEAANAMIAAAAAAH9/f/////+/AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
  61.     AAM8WBrM+rAEQWmIb5KxiWjNInCkV32AJHRlGQBgDA7vdN4vUa8tC78qlrCWmvRKsJTquHkp
  62.     ZTKAsiCtWq0JADs=
  63. }
  64. image create photo blt::tv::activeOpenFolder -format gif -data {
  65.     R0lGODlhEAANAMIAAAAAAH9/f/////+/AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
  66.     AAM1WBrM+rAEMigJ8c3Kb3OSII6kGABhp1JnaK1VGwjwKwtvHqNzzd263M3H4n2OH1QBwGw6
  67.     nQkAOw==
  68. }
  69.  
  70. if { $tcl_platform(platform) == "windows" } {
  71.     if { $tk_version >= 8.3 } {
  72.     set cursor "@[file join $blt_library treeview.cur]"
  73.     } else {
  74.     set cursor "size_we"
  75.     }
  76.     option add *${className}.ResizeCursor [list $cursor]
  77. } else {
  78.     option add *${className}.ResizeCursor \
  79.     "@$blt_library/treeview.xbm $blt_library/treeview_m.xbm black white"
  80. }
  81.  
  82. # ----------------------------------------------------------------------
  83. #
  84. # Initialize --
  85. #
  86. #    Invoked by internally by Treeview_Init routine.  Initializes
  87. #    the default bindings for the treeview widget entries.  These
  88. #    are local to the widget, so they can't be set through the
  89. #    widget's class bind tags.
  90. #
  91. # ----------------------------------------------------------------------
  92. proc blt::tv::Initialize { w } {
  93.     #
  94.     # Active entry bindings
  95.     #
  96.     $w bind Entry <Enter> { 
  97.     %W entry highlight current 
  98.     }
  99.     $w bind Entry <Leave> { 
  100.     %W entry highlight "" 
  101.     }
  102.  
  103.     #
  104.     # Button bindings
  105.     #
  106.     $w button bind all <ButtonRelease-1> {
  107.     %W see -anchor nw current
  108.     %W toggle current
  109.     }
  110.     $w button bind all <Enter> {
  111.     %W button highlight current
  112.     }
  113.     $w button bind all <Leave> {
  114.     %W button highlight ""
  115.     }
  116.  
  117.     #
  118.     # ButtonPress-1
  119.     #
  120.     #    Performs the following operations:
  121.     #
  122.     #    1. Clears the previous selection.
  123.     #    2. Selects the current entry.
  124.     #    3. Sets the focus to this entry.
  125.     #    4. Scrolls the entry into view.
  126.     #    5. Sets the selection anchor to this entry, just in case
  127.     #       this is "multiple" mode.
  128.     #
  129.     
  130.     $w bind Entry <ButtonPress-1> {     
  131.     blt::tv::SetSelectionAnchor %W current
  132.     set blt::tv::scroll 1
  133.     }
  134.  
  135.     $w bind Entry <Double-ButtonPress-1> {
  136.     %W toggle current
  137.     }
  138.  
  139.     #
  140.     # B1-Motion
  141.     #
  142.     #    For "multiple" mode only.  Saves the current location of the
  143.     #    pointer for auto-scrolling.  Resets the selection mark.  
  144.     #
  145.     $w bind Entry <B1-Motion> { 
  146.     set blt::tv::x %x
  147.     set blt::tv::y %y
  148.     set index [%W nearest %x %y]
  149.     if { [%W cget -selectmode] == "multiple" } {
  150.         %W selection mark $index
  151.     } else {
  152.         blt::tv::SetSelectionAnchor %W $index
  153.     }
  154.     }
  155.  
  156.     #
  157.     # ButtonRelease-1
  158.     #
  159.     #    For "multiple" mode only.  
  160.     #
  161.     $w bind Entry <ButtonRelease-1> { 
  162.     if { [%W cget -selectmode] == "multiple" } {
  163.         %W selection anchor current
  164.     }
  165.     after cancel $blt::tv::afterId
  166.     set blt::tv::scroll 0
  167.     }
  168.  
  169.     #
  170.     # Shift-ButtonPress-1
  171.     #
  172.     #    For "multiple" mode only.
  173.     #
  174.  
  175.     $w bind Entry <Shift-ButtonPress-1> { 
  176.     if { [%W cget -selectmode] == "multiple" && [%W selection present] } {
  177.         if { [%W index anchor] == "" } {
  178.         %W selection anchor current
  179.         }
  180.         set index [%W index anchor]
  181.         %W selection clearall
  182.         %W selection set $index current
  183.     } else {
  184.         blt::tv::SetSelectionAnchor %W current
  185.     }
  186.     }
  187.     $w bind Entry <Shift-Double-ButtonPress-1> {
  188.     # do nothing
  189.     }
  190.     $w bind Entry <Shift-B1-Motion> { 
  191.     # do nothing
  192.     }
  193.     $w bind Entry <Shift-ButtonRelease-1> { 
  194.     after cancel $blt::tv::afterId
  195.     set blt::tv::scroll 0
  196.     }
  197.  
  198.     #
  199.     # Control-ButtonPress-1
  200.     #
  201.     #    For "multiple" mode only.  
  202.     #
  203.     $w bind Entry <Control-ButtonPress-1> { 
  204.     if { [%W cget -selectmode] == "multiple" } {
  205.         set index [%W index current]
  206.         %W selection toggle $index
  207.         %W selection anchor $index
  208.     } else {
  209.         blt::tv::SetSelectionAnchor %W current
  210.     }
  211.     }
  212.     $w bind Entry <Control-Double-ButtonPress-1> {
  213.     # do nothing
  214.     }
  215.     $w bind Entry <Control-B1-Motion> { 
  216.     # do nothing
  217.     }
  218.     $w bind Entry <Control-ButtonRelease-1> { 
  219.     after cancel $blt::tv::afterId
  220.     set blt::tv::scroll 0
  221.     }
  222.  
  223.     $w bind Entry <Control-Shift-ButtonPress-1> { 
  224.     if { [%W cget -selectmode] == "multiple" && [%W selection present] } {
  225.         if { [%W index anchor] == "" } {
  226.         %W selection anchor current
  227.         }
  228.         if { [%W selection includes anchor] } {
  229.         %W selection set anchor current
  230.         } else {
  231.         %W selection clear anchor current
  232.         %W selection set current
  233.         }
  234.     } else {
  235.         blt::tv::SetSelectionAnchor %W current
  236.     }
  237.     }
  238.     $w bind Entry <Control-Shift-Double-ButtonPress-1> {
  239.     # do nothing
  240.     }
  241.     $w bind Entry <Control-Shift-B1-Motion> { 
  242.     # do nothing
  243.     }
  244.  
  245.     $w bind Entry <Shift-ButtonPress-3> { 
  246.     blt::tv::EditColumn %W %X %Y
  247.     }
  248.  
  249.     $w column bind all <Enter> {
  250.     %W column highlight [%W column current]
  251.     }
  252.     $w column bind all <Leave> {
  253.     %W column highlight ""
  254.     }
  255.     $w column bind Rule <Enter> {
  256.     %W column highlight [%W column current]
  257.     %W column resize activate [%W column current]
  258.     }
  259.     $w column bind Rule <Leave> {
  260.     %W column highlight ""
  261.     %W column resize activate ""
  262.     }
  263.     $w column bind Rule <ButtonPress-1> {
  264.     %W column resize anchor %x
  265.     }
  266.     $w column bind Rule <B1-Motion> {
  267.     %W column resize mark %x
  268.     }
  269.     $w column bind Rule <ButtonRelease-1> {
  270.     %W column configure [%W column current] -width [%W column resize set]
  271.     }
  272.     $w column bind all <ButtonPress-1> {
  273.     set blt::tv::column [%W column current]
  274.     %W column configure $blt::tv::column -titlerelief sunken
  275.     }
  276.     $w column bind all <ButtonRelease-1> {
  277.     set column [%W column current]
  278.     if { $column != "" } {
  279.         %W column invoke $column
  280.     }
  281.     %W column configure $blt::tv::column -titlerelief raised
  282.     }
  283.     $w bind TextBoxStyle <ButtonPress-3> { 
  284.     if { [%W edit -root -test %X %Y] } {
  285.         break
  286.     }
  287.     }
  288.     $w bind TextBoxStyle <ButtonRelease-3> { 
  289.     if { [%W edit -root -test %X %Y] } {
  290.         blt::tv::EditColumn %W %X %Y
  291.         break
  292.     }
  293.     }
  294.     $w bind CheckBoxStyle <Enter> { 
  295.     set column [%W column current]
  296.     if { [%W column cget $column -edit] } {
  297.         %W style activate current $column
  298.     } 
  299.     }
  300.     $w bind CheckBoxStyle <Leave> { 
  301.     %W style activate ""
  302.     }
  303.     $w bind CheckBoxStyle <ButtonPress-1> { 
  304.     set column [%W column current]
  305.     if { [%W column cget $column -edit] } {
  306.         break
  307.     }
  308.     }
  309.     $w bind CheckBoxStyle <B1-Motion> { 
  310.     set column [%W column current]
  311.     if { [%W column cget $column -edit] } {
  312.         break
  313.     }
  314.     }
  315.     $w bind CheckBoxStyle <ButtonRelease-1> { 
  316.     if { [%W edit -root -test %X %Y] } {
  317.         %W edit -root %X %Y
  318.         break
  319.     }
  320.     }
  321.     $w bind ComboBoxStyle <ButtonPress-1> { 
  322.     set column [%W column current]
  323.     if { [%W column cget $column -edit] } {
  324.         break
  325.     }
  326.     }
  327.     $w bind ComboBoxStyle <ButtonRelease-1> { 
  328.     if { [%W edit -root -test %X %Y] } {
  329.         %W edit -root %X %Y
  330.         break
  331.     }
  332.     }
  333. }
  334.  
  335. # ----------------------------------------------------------------------
  336. #
  337. # AutoScroll --
  338. #
  339. #    Invoked when the user is selecting elements in a treeview
  340. #    widget and drags the mouse pointer outside of the widget.
  341. #    Scrolls the view in the direction of the pointer.
  342. #
  343. # ----------------------------------------------------------------------
  344. proc blt::tv::AutoScroll { w } {
  345.     if { ![winfo exists $w] } {
  346.     return
  347.     }
  348.     set x $blt::tv::x
  349.     set y $blt::tv::y
  350.  
  351.     set index [$w nearest $x $y]
  352.  
  353.     if {$y >= [winfo height $w]} {
  354.     $w yview scroll 1 units
  355.     set neighbor down
  356.     } elseif {$y < 0} {
  357.     $w yview scroll -1 units
  358.     set neighbor up
  359.     } else {
  360.     set neighbor $index
  361.     }
  362.     if { [$w cget -selectmode] == "single" } {
  363.     blt::tv::SetSelectionAnchor $w $neighbor
  364.     } else {
  365.     $w selection mark $index
  366.     }
  367.     set ::blt::tv::afterId [after 50 blt::tv::AutoScroll $w]
  368. }
  369.  
  370. proc blt::tv::SetSelectionAnchor { w tagOrId } {
  371.     set index [$w index $tagOrId]
  372.     # If the anchor hasn't changed, don't do anything
  373.     if { $index != [$w index anchor] } {
  374.     $w selection clearall
  375.     $w see $index
  376.     $w focus $index
  377.     $w selection set $index
  378.     $w selection anchor $index
  379.     }
  380. }
  381.  
  382. # ----------------------------------------------------------------------
  383. #
  384. # MoveFocus --
  385. #
  386. #    Invoked by KeyPress bindings.  Moves the active selection to
  387. #    the entry <where>, which is an index such as "up", "down",
  388. #    "prevsibling", "nextsibling", etc.
  389. #
  390. # ----------------------------------------------------------------------
  391. proc blt::tv::MoveFocus { w tagOrId } {
  392.     catch {$w focus $tagOrId}
  393.     if { [$w cget -selectmode] == "single" } {
  394.         $w selection clearall
  395.         $w selection set focus
  396.     $w selection anchor focus
  397.     }
  398.     $w see focus
  399. }
  400.  
  401. # ----------------------------------------------------------------------
  402. #
  403. # MovePage --
  404. #
  405. #    Invoked by KeyPress bindings.  Pages the current view up or
  406. #    down.  The <where> argument should be either "top" or
  407. #    "bottom".
  408. #
  409. # ----------------------------------------------------------------------
  410. proc blt::tv::MovePage { w where } {
  411.  
  412.     # If the focus is already at the top/bottom of the window, we want
  413.     # to scroll a page. It's really one page minus an entry because we
  414.     # want to see the last entry on the next/last page.
  415.     if { [$w index focus] == [$w index view.$where] } {
  416.         if {$where == "top"} {
  417.         $w yview scroll -1 pages
  418.         $w yview scroll 1 units
  419.         } else {
  420.         $w yview scroll 1 pages
  421.         $w yview scroll -1 units
  422.         }
  423.     }
  424.     update
  425.  
  426.     # Adjust the entry focus and the view.  Also activate the entry.
  427.     # just in case the mouse point is not in the widget.
  428.     $w entry highlight view.$where
  429.     $w focus view.$where
  430.     $w see view.$where
  431.     if { [$w cget -selectmode] == "single" } {
  432.         $w selection clearall
  433.         $w selection set focus
  434.     }
  435. }
  436.  
  437. # ----------------------------------------------------------------------
  438. #
  439. # NextMatch --
  440. #
  441. #    Invoked by KeyPress bindings.  Searches for an entry that
  442. #    starts with the letter <char> and makes that entry active.
  443. #
  444. # ----------------------------------------------------------------------
  445. proc blt::tv::NextMatch { w key } {
  446.     if {[string match {[ -~]} $key]} {
  447.     set last [$w index focus]
  448.     set next [$w index next]
  449.     while { $next != $last } {
  450.         set label [$w entry cget $next -label]
  451.         set label [string index $label 0]
  452.         if { [string tolower $label] == [string tolower $key] } {
  453.         break
  454.         }
  455.         set next [$w index -at $next next]
  456.     }
  457.     $w focus $next
  458.     if {[$w cget -selectmode] == "single"} {
  459.         $w selection clearall
  460.         $w selection set focus
  461.     }
  462.     $w see focus
  463.     }
  464. }
  465.  
  466. #------------------------------------------------------------------------
  467. #
  468. # InsertText --
  469. #
  470. #    Inserts a text string into an entry at the insertion cursor.  
  471. #    If there is a selection in the entry, and it covers the point 
  472. #    of the insertion cursor, then delete the selection before 
  473. #    inserting.
  474. #
  475. # Arguments:
  476. #    w     Widget where to insert the text.
  477. #    text    Text string to insert (usually just a single character)
  478. #
  479. #------------------------------------------------------------------------
  480. proc blt::tv::InsertText { w text } {
  481.     if { [string length $text] > 0 } {
  482.     set index [$w index insert]
  483.     if { ($index >= [$w index sel.first]) && 
  484.          ($index <= [$w index sel.last]) } {
  485.         $w delete sel.first sel.last
  486.     }
  487.     $w insert $index $text
  488.     }
  489. }
  490.  
  491. #------------------------------------------------------------------------
  492. #
  493. # Transpose -
  494. #
  495. #    This procedure implements the "transpose" function for entry
  496. #    widgets.  It tranposes the characters on either side of the
  497. #    insertion cursor, unless the cursor is at the end of the line.
  498. #    In this case it transposes the two characters to the left of
  499. #    the cursor.  In either case, the cursor ends up to the right
  500. #    of the transposed characters.
  501. #
  502. # Arguments:
  503. #    w     The entry window.
  504. #
  505. #------------------------------------------------------------------------
  506. proc blt::tv::Transpose { w } {
  507.     set i [$w index insert]
  508.     if {$i < [$w index end]} {
  509.     incr i
  510.     }
  511.     set first [expr {$i-2}]
  512.     if {$first < 0} {
  513.     return
  514.     }
  515.     set new [string index [$w get] [expr {$i-1}]][string index [$w get] $first]
  516.     $w delete $first $i
  517.     $w insert insert $new
  518. }
  519.  
  520. #------------------------------------------------------------------------
  521. #
  522. # GetSelection --
  523. #
  524. #    Returns the selected text of the entry with respect to the
  525. #    -show option.
  526. #
  527. # Arguments:
  528. #    w          Entry window from which the text to get
  529. #
  530. #------------------------------------------------------------------------
  531.  
  532. proc blt::tv::GetSelection { w } {
  533.     set text [string range [$w get] [$w index sel.first] \
  534.                        [expr [$w index sel.last] - 1]]
  535.     if {[$w cget -show] != ""} {
  536.     regsub -all . $text [string index [$w cget -show] 0] text
  537.     }
  538.     return $text
  539. }
  540.  
  541. proc blt::tv::EditColumn { w x y } {
  542.     $w see current
  543.     if { [winfo exists $w.edit] } {
  544.     destroy $w.edit
  545.     }
  546.     if { ![$w edit -root -test $x $y] } {
  547.     return
  548.     }
  549.     $w edit -root $x $y
  550.     update
  551.     focus $w.edit
  552.     $w.edit selection range 0 end
  553.     grab set $w.edit
  554.     tkwait window $w.edit
  555.     grab release $w.edit
  556. }
  557.  
  558. # ButtonPress assignments
  559. #
  560. #    B1-Enter    start auto-scrolling
  561. #    B1-Leave    stop auto-scrolling
  562. #    ButtonPress-2    start scan
  563. #    B2-Motion    adjust scan
  564. #    ButtonRelease-2 stop scan
  565. #
  566.  
  567. bind ${className} <ButtonPress-2> {
  568.     set blt::tv::cursor [%W cget -cursor]
  569.     %W configure -cursor hand1
  570.     %W scan mark %x %y
  571. }
  572.  
  573. bind ${className} <B2-Motion> {
  574.     %W scan dragto %x %y
  575. }
  576.  
  577. bind ${className} <ButtonRelease-2> {
  578.     %W configure -cursor $blt::tv::cursor
  579. }
  580.  
  581. bind ${className} <B1-Leave> {
  582.     if { $blt::tv::scroll } {
  583.     blt::tv::AutoScroll %W 
  584.     }
  585. }
  586.  
  587. bind ${className} <B1-Enter> {
  588.     after cancel $blt::tv::afterId
  589. }
  590.  
  591. # KeyPress assignments
  592. #
  593. #    Up            
  594. #    Down
  595. #    Shift-Up
  596. #    Shift-Down
  597. #    Prior (PageUp)
  598. #    Next  (PageDn)
  599. #    Left
  600. #    Right
  601. #    space        Start selection toggle of entry currently with focus.
  602. #    Return        Start selection toggle of entry currently with focus.
  603. #    Home
  604. #    End
  605. #    F1
  606. #    F2
  607. #    ASCII char    Go to next open entry starting with character.
  608. #
  609. # KeyRelease
  610. #
  611. #    space        Stop selection toggle of entry currently with focus.
  612. #    Return        Stop selection toggle of entry currently with focus.
  613.  
  614.  
  615. bind ${className} <KeyPress-Up> {
  616.     blt::tv::MoveFocus %W up
  617.     if { $blt::tv::space } {
  618.     %W selection toggle focus
  619.     }
  620. }
  621.  
  622. bind ${className} <KeyPress-Down> {
  623.     blt::tv::MoveFocus %W down
  624.     if { $blt::tv::space } {
  625.     %W selection toggle focus
  626.     }
  627. }
  628.  
  629. bind ${className} <Shift-KeyPress-Up> {
  630.     blt::tv::MoveFocus %W prevsibling
  631. }
  632.  
  633. bind ${className} <Shift-KeyPress-Down> {
  634.     blt::tv::MoveFocus %W nextsibling
  635. }
  636.  
  637. bind ${className} <KeyPress-Prior> {
  638.     blt::tv::MovePage %W top
  639. }
  640.  
  641. bind ${className} <KeyPress-Next> {
  642.     blt::tv::MovePage %W bottom
  643. }
  644.  
  645. bind ${className} <KeyPress-Left> {
  646.     %W close focus
  647. }
  648. bind ${className} <KeyPress-Right> {
  649.     %W open focus
  650.     %W see focus -anchor w
  651. }
  652.  
  653. bind ${className} <KeyPress-space> {
  654.     if { [%W cget -selectmode] == "single" } {
  655.     if { [%W selection includes focus] } {
  656.         %W selection clearall
  657.     } else {
  658.         %W selection clearall
  659.         %W selection set focus
  660.     }
  661.     } else {
  662.     %W selection toggle focus
  663.     }
  664.     set blt::tv::space on
  665. }
  666.  
  667. bind ${className} <KeyRelease-space> { 
  668.     set blt::tv::space off
  669. }
  670.  
  671. bind ${className} <KeyPress-Return> {
  672.     blt::tv::MoveFocus %W focus
  673.     set blt::tv::space on
  674. }
  675.  
  676. bind ${className} <KeyRelease-Return> { 
  677.     set blt::tv::space off
  678. }
  679.  
  680. bind ${className} <KeyPress> {
  681.     blt::tv::NextMatch %W %A
  682. }
  683.  
  684. bind ${className} <KeyPress-Home> {
  685.     blt::tv::MoveFocus %W top
  686. }
  687.  
  688. bind ${className} <KeyPress-End> {
  689.     blt::tv::MoveFocus %W bottom
  690. }
  691.  
  692. bind ${className} <KeyPress-F1> {
  693.     %W open -r root
  694. }
  695.  
  696. bind ${className} <KeyPress-F2> {
  697.     eval %W close -r [%W entry children root] 
  698. }
  699.  
  700. #
  701. # Differences between id "current" and operation nearest.
  702. #
  703. #    set index [$w index current]
  704. #    set index [$w nearest $x $y]
  705. #
  706. #    o Nearest gives you the closest entry.
  707. #    o current is "" if
  708. #       1) the pointer isn't over an entry.
  709. #       2) the pointer is over a open/close button.
  710. #       3) 
  711. #
  712.  
  713. #
  714. #  Edit mode assignments
  715. #
  716. #    ButtonPress-3   Enables/disables edit mode on entry.  Sets focus to 
  717. #            entry.
  718. #
  719. #  KeyPress
  720. #
  721. #    Left        Move insertion position to previous.
  722. #    Right        Move insertion position to next.
  723. #    Up        Move insertion position up one line.
  724. #    Down        Move insertion position down one line.
  725. #    Return        End edit mode.
  726. #    Shift-Return    Line feed.
  727. #    Home        Move to first position.
  728. #    End        Move to last position.
  729. #    ASCII char    Insert character left of insertion point.
  730. #    Del        Delete character right of insertion point.
  731. #    Delete        Delete character left of insertion point.
  732. #    Ctrl-X        Cut
  733. #    Ctrl-V        Copy
  734. #    Ctrl-P        Paste
  735. #    
  736. #  KeyRelease
  737. #
  738. #    ButtonPress-1    Start selection if in entry, otherwise clear selection.
  739. #    B1-Motion    Extend/reduce selection.
  740. #    ButtonRelease-1 End selection if in entry, otherwise use last
  741. #            selection.
  742. #    B1-Enter    Disabled.
  743. #    B1-Leave    Disabled.
  744. #    ButtonPress-2    Same as above.
  745. #    B2-Motion    Same as above.
  746. #    ButtonRelease-2    Same as above.
  747. #    
  748. #
  749.  
  750.  
  751. # Standard Motif bindings:
  752.  
  753. bind ${className}Editor <ButtonPress-1> {
  754.     %W icursor @%x,%y
  755.     %W selection clear
  756. }
  757.  
  758. bind ${className}Editor <Left> {
  759.     %W icursor last
  760.     %W selection clear
  761. }
  762.  
  763. bind ${className}Editor <Right> {
  764.     %W icursor next
  765.     %W selection clear
  766. }
  767.  
  768. bind ${className}Editor <Shift-Left> {
  769.     set new [expr {[%W index insert] - 1}]
  770.     if {![%W selection present]} {
  771.     %W selection from insert
  772.     %W selection to $new
  773.     } else {
  774.     %W selection adjust $new
  775.     }
  776.     %W icursor $new
  777. }
  778.  
  779. bind ${className}Editor <Shift-Right> {
  780.     set new [expr {[%W index insert] + 1}]
  781.     if {![%W selection present]} {
  782.     %W selection from insert
  783.     %W selection to $new
  784.     } else {
  785.     %W selection adjust $new
  786.     }
  787.     %W icursor $new
  788. }
  789.  
  790. bind ${className}Editor <Home> {
  791.     %W icursor 0
  792.     %W selection clear
  793. }
  794. bind ${className}Editor <Shift-Home> {
  795.     set new 0
  796.     if {![%W selection present]} {
  797.     %W selection from insert
  798.     %W selection to $new
  799.     } else {
  800.     %W selection adjust $new
  801.     }
  802.     %W icursor $new
  803. }
  804. bind ${className}Editor <End> {
  805.     %W icursor end
  806.     %W selection clear
  807. }
  808. bind ${className}Editor <Shift-End> {
  809.     set new end
  810.     if {![%W selection present]} {
  811.     %W selection from insert
  812.     %W selection to $new
  813.     } else {
  814.     %W selection adjust $new
  815.     }
  816.     %W icursor $new
  817. }
  818.  
  819. bind ${className}Editor <Delete> {
  820.     if { [%W selection present]} {
  821.     %W delete sel.first sel.last
  822.     } else {
  823.     %W delete insert
  824.     }
  825. }
  826.  
  827. bind ${className}Editor <BackSpace> {
  828.     if { [%W selection present] } {
  829.     %W delete sel.first sel.last
  830.     } else {
  831.     set index [expr [%W index insert] - 1]
  832.     if { $index >= 0 } {
  833.         %W delete $index $index
  834.     }
  835.     }
  836. }
  837.  
  838. bind ${className}Editor <Control-space> {
  839.     %W selection from insert
  840. }
  841.  
  842. bind ${className}Editor <Select> {
  843.     %W selection from insert
  844. }
  845.  
  846. bind ${className}Editor <Control-Shift-space> {
  847.     %W selection adjust insert
  848. }
  849.  
  850. bind ${className}Editor <Shift-Select> {
  851.     %W selection adjust insert
  852. }
  853.  
  854. bind ${className}Editor <Control-slash> {
  855.     %W selection range 0 end
  856. }
  857.  
  858. bind ${className}Editor <Control-backslash> {
  859.     %W selection clear
  860. }
  861.  
  862. bind ${className}Editor <KeyPress> {
  863.     blt::tv::InsertText %W %A
  864. }
  865.  
  866. # Ignore all Alt, Meta, and Control keypresses unless explicitly bound.
  867. # Otherwise, if a widget binding for one of these is defined, the
  868. # <KeyPress> class binding will also fire and insert the character,
  869. # which is wrong.  Ditto for Escape, Return, and Tab.
  870.  
  871. bind ${className}Editor <Alt-KeyPress> {
  872.     # nothing
  873. }
  874.  
  875. bind ${className}Editor <Meta-KeyPress> {
  876.     # nothing
  877. }
  878.  
  879. bind ${className}Editor <Control-KeyPress> {
  880.     # nothing
  881. }
  882.  
  883. bind ${className}Editor <Escape> { 
  884.     %W cancel 
  885. }
  886.  
  887. bind ${className}Editor <Return> { 
  888.     %W apply 
  889. }
  890.  
  891. bind ${className}Editor <Shift-Return> {
  892.     blt::tv::InsertText %W "\n"
  893. }
  894.  
  895. bind ${className}Editor <KP_Enter> {
  896.     # nothing
  897. }
  898.  
  899. bind ${className}Editor <Tab> {
  900.     # nothing
  901. }
  902.  
  903. if {![string compare $tcl_platform(platform) "macintosh"]} {
  904.     bind ${className}Editor <Command-KeyPress> {
  905.     # nothing
  906.     }
  907. }
  908.  
  909. # On Windows, paste is done using Shift-Insert.  Shift-Insert already
  910. # generates the <<Paste>> event, so we don't need to do anything here.
  911. if { [string compare $tcl_platform(platform) "windows"] != 0 } {
  912.     bind ${className}Editor <Insert> {
  913.     catch {blt::tv::InsertText %W [selection get -displayof %W]}
  914.     }
  915. }
  916.  
  917. # Additional emacs-like bindings:
  918. bind ${className}Editor <ButtonPress-3> {
  919.     set parent [winfo parent %W]
  920.     %W cancel
  921.     after idle {
  922.     blt::tv::EditColumn $parent %X %Y
  923.     }
  924. }
  925.  
  926. bind ${className}Editor <Control-a> {
  927.     %W icursor 0
  928.     %W selection clear
  929. }
  930.  
  931. bind ${className}Editor <Control-b> {
  932.     %W icursor [expr {[%W index insert] - 1}]
  933.     %W selection clear
  934. }
  935.  
  936. bind ${className}Editor <Control-d> {
  937.     %W delete insert
  938. }
  939.  
  940. bind ${className}Editor <Control-e> {
  941.     %W icursor end
  942.     %W selection clear
  943. }
  944.  
  945. bind ${className}Editor <Control-f> {
  946.     %W icursor [expr {[%W index insert] + 1}]
  947.     %W selection clear
  948. }
  949.  
  950. bind ${className}Editor <Control-h> {
  951.     if {[%W selection present]} {
  952.     %W delete sel.first sel.last
  953.     } else {
  954.     set index [expr [%W index insert] - 1]
  955.     if { $index >= 0 } {
  956.         %W delete $index $index
  957.     }
  958.     }
  959. }
  960.  
  961. bind ${className}Editor <Control-k> {
  962.     %W delete insert end
  963. }
  964.  
  965. if 0 {
  966.     bind ${className}Editor <Control-t> {
  967.     blt::tv::Transpose %W
  968.     }
  969.     bind ${className}Editor <Meta-b> {
  970.     %W icursor [blt::tv::PreviousWord %W insert]
  971.     %W selection clear
  972.     }
  973.     bind ${className}Editor <Meta-d> {
  974.     %W delete insert [blt::tv::NextWord %W insert]
  975.     }
  976.     bind ${className}Editor <Meta-f> {
  977.     %W icursor [blt::tv::NextWord %W insert]
  978.     %W selection clear
  979.     }
  980.     bind ${className}Editor <Meta-BackSpace> {
  981.     %W delete [blt::tv::PreviousWord %W insert] insert
  982.     }
  983.     bind ${className}Editor <Meta-Delete> {
  984.     %W delete [blt::tv::PreviousWord %W insert] insert
  985.     }
  986.     # tkEntryNextWord -- Returns the index of the next word position
  987.     # after a given position in the entry.  The next word is platform
  988.     # dependent and may be either the next end-of-word position or the
  989.     # next start-of-word position after the next end-of-word position.
  990.     #
  991.     # Arguments:
  992.     # w -        The entry window in which the cursor is to move.
  993.     # start -    Position at which to start search.
  994.     
  995.     if {![string compare $tcl_platform(platform) "windows"]}  {
  996.     proc blt::tv::NextWord {w start} {
  997.         set pos [tcl_endOfWord [$w get] [$w index $start]]
  998.         if {$pos >= 0} {
  999.         set pos [tcl_startOfNextWord [$w get] $pos]
  1000.         }
  1001.         if {$pos < 0} {
  1002.         return end
  1003.         }
  1004.         return $pos
  1005.     }
  1006.     } else {
  1007.     proc blt::tv::NextWord {w start} {
  1008.         set pos [tcl_endOfWord [$w get] [$w index $start]]
  1009.         if {$pos < 0} {
  1010.         return end
  1011.         }
  1012.         return $pos
  1013.     }
  1014.     }
  1015.     
  1016.     # PreviousWord --
  1017.     #
  1018.     # Returns the index of the previous word position before a given
  1019.     # position in the entry.
  1020.     #
  1021.     # Arguments:
  1022.     # w -        The entry window in which the cursor is to move.
  1023.     # start -    Position at which to start search.
  1024.     
  1025.     proc blt::tv::PreviousWord {w start} {
  1026.     set pos [tcl_startOfPreviousWord [$w get] [$w index $start]]
  1027.     if {$pos < 0} {
  1028.         return 0
  1029.     }
  1030.     return $pos
  1031.     }
  1032. }
  1033.  
  1034.